unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, RzButton, Grids, BaseGrid, AdvGrid, DB, ADODB,Class_ReadCard;

type
  TForm1 = class(TForm)
    ADVGrid1: TAdvStringGrid;
    RzButton1: TRzButton;
    RzButton2: TRzButton;
    RzButton3: TRzButton;
    ADOCon: TADOConnection;
    RzButton4: TRzButton;
    procedure RzButton1Click(Sender: TObject);
    procedure RzButton3Click(Sender: TObject);
    procedure RzButton4Click(Sender: TObject);
  private
  public
    { Public declarations }
    procedure FillAdvGrid;
    function  EchoSQL:string;
    procedure SetGridColVisible(AValue:Boolean;AIndex:Integer);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function TForm1.EchoSQL: string;
begin
  Result:='Select ReadCard.*,A.AssetSortNames AS ASS_AssSort,B.Name AS Depart_Name'
         +'   From AssetSort A ,Department B,'
         +'   (Select D.ID,D.Ass_ID,D.Assetsdept,D.Code,D.AssetBarCode AS ASS_BarCode,D.SerialCode  AS ASS_Code,D.AssetsName AS ASS_Name,D.AssetsStandard AS ASS_Standard,'
         +'   D.AssetsNum AS ASS_Count,D.Assetsprice AS ASS_Value, D.DpreciationAdd AS ASS_AddDep,D.LeftPrice AS ASS_LeftValue,D.AssetsUsedate AS ASS_UseDate,D.KJQJ_BH AS ASS_AccMonth,D.KJND_BH AS ASS_AccYear,'
         +'   D.YearCount AS ASS_UseYear,D.Remarks AS ASS_Memo, D.Assets_Tag AS ASS_AssTAG,C.Name AS Employ_Name From AssetCard D Left Join Employee C On D.Assetsuser=C.ID) AS  ReadCard'
         +'   Where A.ID=ReadCard.Ass_ID'
         +'   AND   B.ID=ReadCard.AssetsDept'
         +'   Order by ReadCard.ID';


end;

procedure TForm1.FillAdvGrid;
var
  AList:TList;
  I:Integer;
  ReadCard:TReadCard;
begin
  AList:=TReadCard.ListDB(EchoSQL,Self.ADOCon);

  self.ADVGrid1.RowCount:=1400;

  for i:=0 to AList.Count-1 do
  begin
    ReadCard:=TReadCard(AList.Items[I]);
    ADVGrid1.Objects[0,I+1]:=ReadCard;
    with ADVGrid1 do
    begin
      Ints[0,i+1]:=I+1;
      Cells[1,I+1]:=ReadCard.ASS_BarCode;
      Cells[2,I+1]:=ReadCard.ASS_Code;
      Cells[3,I+1]:=ReadCard.ASS_Name;
      Cells[4,I+1]:=ReadCard.ASS_Standard;
      Cells[5,I+1]:=ReadCard.ASS_AssSort;
      Cells[6,I+1]:=ReadCard.ASS_Memo;
      Cells[7,I+1]:=ReadCard.Depart_Name;
      Cells[8,I+1]:=ReadCard.Employ_Name;
      Ints[9,I+1]:=ReadCard.ASS_Count;
      Ints[10,I+1]:=ReadCard.ASS_UseDate;
      Ints[11,I+1]:=ReadCard.ASS_UseYear;
      Floats[12,I+1]:=ReadCard.ASS_Value;
      Floats[13,I+1]:=ReadCard.ASS_ADDDep;
      Cells[14,I+1]:=ReadCard.Code;
      Ints[15,I+1]:=ReadCard.ASS_AccYear;
      Ints[16,I+1]:=ReadCard.ASS_AccMonth;
      Floats[17,I+1]:=ReadCard.ASS_LeftValue;
      
    end;

  end;
end;

procedure TForm1.RzButton1Click(Sender: TObject);
begin
  FillAdvGrid;
end;



procedure TForm1.SetGridColVisible(AValue: Boolean; AIndex: Integer);
begin
  if AValue then
  begin
    ADVGrid1.UnHideColumn(AIndex);
  end else
  begin
    ADVGrid1.HideColumn(AIndex);
  end;
end;

procedure TForm1.RzButton3Click(Sender: TObject);
begin
  Self.SetGridColVisible(False,1);
end;

procedure TForm1.RzButton4Click(Sender: TObject);
begin
  Self.SetGridColVisible(True,1);
end;

end.
